/*
*Copyright (c) Nikhil Jain.
*Project ICARUS, communications and 
*artificial intelligence.
*/



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package javadrone.server;

//~--- non-JDK imports --------------------------------------------------------

import javadrone.command.CommandQueue;

import javadrone.server.listeners.BootStateChangeListener;
import javadrone.server.listeners.NavigationStateChangeListener;
import javadrone.server.simulation.GenericDroneInstructor;

import javadrone.util.RapidImageDisplayer;

//~--- JDK imports ------------------------------------------------------------

import java.rmi.RemoteException;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

/**
 *
 * @author Nikzzay
 */
public class DroneServer extends ServerImpl {
    public DroneServer(String serverName) throws NamingException, RemoteException {
        super(serverName);
    }

    @Override
    public void hasRegistered(DroneImpl testDrone) {
        System.out.println("Link to client acquired...");

        GenericDroneInstructor gdi = new GenericDroneInstructor(testDrone);
        StateImpl              s   = testDrone.getCompleteState();
        ImageConsumer          iC  = new ImageConsumer(100);

        s.addVideoStateChangeListener(iC);

        final JFrame vidDisp = new JFrame("VideoFeed");

        vidDisp.setBounds(0, 0, 500, 500);

        final RapidImageDisplayer rid = new RapidImageDisplayer(iC);

        rid.setBounds(0, 0, 500, 500);
        vidDisp.getContentPane().add(rid);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                vidDisp.setVisible(true);
            }
        });
        gdi.start();
        rid.start();
        System.out.println("Server successfully started...");
    }

    public static void main(String args[]) {
        try {
            System.setProperty("java.rmi.server.codebase",
                               "file:\\" + System.getProperty("user.dir") + "\\build\\classes\\");

            DroneServer DS = new DroneServer("DRONE SERVER");

            System.out.println("Waiting for clients to connect...");
        } catch (NamingException ex) {
            Logger.getLogger(DroneServer.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(DroneServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
